package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo9 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            UerInfo uerInfo = InputUtil.getInputObject(new UerInfo(), "欢迎注册，宝贝~");
            String sql = "INSERT INTO userinfo(username,password,nickname,age) VALUES (?,?,?,?)";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, uerInfo.getUsername());
            preparedStatement.setString(2, uerInfo.getPassword());
            preparedStatement.setString(3, uerInfo.getNickname());
            preparedStatement.setInt(4, uerInfo.getAge());
            int number = preparedStatement.executeUpdate();
            System.out.println(number > 0 ? "注册成功" : "注册失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
